package com.erp.common.web;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.erp.framework.controller.form.SimpleUserStyleForm;
import com.erp.framework.util.CommonUtil;

public class SearchForm extends SimpleUserStyleForm {
    private boolean isExclusive = false;
    private boolean isAutoSearch = false;
    private boolean showFromTo = true;
    private boolean showSearchBtn = true;
    private boolean showOkCancelBtn = true;
    private boolean showSelectBox = true;

    public boolean getIsExclusive() {
        return isExclusive;
    }

    public void setIsExclusive(boolean isExclusive) {
        this.isExclusive = isExclusive;
    }

    public boolean isAutoSearch() {
        return isAutoSearch;
    }

    public void setAutoSearch(boolean isAutoSearch) {
        this.isAutoSearch = isAutoSearch;
    }

    private HashMap params = new HashMap();

    public HashMap getParams() {
        return params;
    }

    public void setParams(HashMap params) {
        this.params = params;
    }

    private String field1;
    private String field2;
    private String field3;
    private String field4;
    private String field5;
    private String field6;
    private String field7;
    private String field8;
    private String field9;
    private String field10;
    private String field11;
    private String field12;
    private String field13;
    private String field14;
    private String field15;
    private String field16;
    private String field17;
    private String field18;
    private String field19;
    private String field20;

    private String needResize;
    private String[] resizeTo;

    public String getField1() {
        return field1;
    }

    public String getField2() {
        return field2;
    }

    public String getField3() {
        return field3;
    }

    public String getField4() {
        return field4;
    }

    public String getField5() {
        return field5;
    }

    public String getField6() {
        return field6;
    }

    public String getField7() {
        return field7;
    }

    public String getField8() {
        return field8;
    }

    public String getField9() {
        return field9;
    }

    public String getField10() {
        return field10;
    }

    public String getField11() {
        return field11;
    }

    public String getField12() {
        return field12;
    }

    public String getField13() {
        return field13;
    }

    public String getField14() {
        return field14;
    }

    public String getField15() {
        return field15;
    }

    public String getField16() {
        return field16;
    }

    public String getField17() {
        return field17;
    }

    public String getField18() {
        return field18;
    }

    public String getField19() {
        return field19;
    }

    public String getField20() {
        return field20;
    }

    public void setField1(String field1) {
        this.field1 = field1;
    }

    public void setField2(String field2) {
        this.field2 = field2;
    }

    public void setField3(String field3) {
        this.field3 = field3;
    }

    public void setField4(String field4) {
        this.field4 = field4;
    }

    public void setField5(String field5) {
        this.field5 = field5;
    }

    public void setField6(String field6) {
        this.field6 = field6;
    }

    public void setField7(String field7) {
        this.field7 = field7;
    }

    public void setField8(String field8) {
        this.field8 = field8;
    }

    public void setField9(String field9) {
        this.field9 = field9;
    }

    public void setField10(String field10) {
        this.field10 = field10;
    }

    public void setField11(String field11) {
        this.field11 = field11;
    }

    public void setField12(String field12) {
        this.field12 = field12;
    }

    public void setField13(String field13) {
        this.field13 = field13;
    }

    public void setField14(String field14) {
        this.field14 = field14;
    }

    public void setField15(String field15) {
        this.field15 = field15;
    }

    public void setField16(String field16) {
        this.field16 = field16;
    }

    public void setField17(String field17) {
        this.field17 = field17;
    }

    public void setField18(String field18) {
        this.field18 = field18;
    }

    public void setField19(String field19) {
        this.field19 = field19;
    }

    public void setField20(String field20) {
        this.field20 = field20;
    }

    private String fieldTo1;
    private String fieldTo2;
    private String fieldTo3;
    private String fieldTo4;
    private String fieldTo5;
    private String fieldTo6;
    private String fieldTo7;
    private String fieldTo8;
    private String fieldTo9;
    private String fieldTo10;
    private String fieldTo11;
    private String fieldTo12;
    private String fieldTo13;
    private String fieldTo14;
    private String fieldTo15;
    private String fieldTo16;
    private String fieldTo17;
    private String fieldTo18;
    private String fieldTo19;
    private String fieldTo20;

    public String getFieldTo1() {
        return fieldTo1;
    }

    public String getFieldTo2() {
        return fieldTo2;
    }

    public String getFieldTo3() {
        return fieldTo3;
    }

    public String getFieldTo4() {
        return fieldTo4;
    }

    public String getFieldTo5() {
        return fieldTo5;
    }

    public String getFieldTo6() {
        return fieldTo6;
    }

    public String getFieldTo7() {
        return fieldTo7;
    }

    public String getFieldTo8() {
        return fieldTo8;
    }

    public String getFieldTo9() {
        return fieldTo9;
    }

    public String getFieldTo10() {
        return fieldTo10;
    }

    public String getFieldTo11() {
        return fieldTo11;
    }

    public String getFieldTo12() {
        return fieldTo12;
    }

    public String getFieldTo13() {
        return fieldTo13;
    }

    public String getFieldTo14() {
        return fieldTo14;
    }

    public String getFieldTo15() {
        return fieldTo15;
    }

    public String getFieldTo16() {
        return fieldTo16;
    }

    public String getFieldTo17() {
        return fieldTo17;
    }

    public String getFieldTo18() {
        return fieldTo18;
    }

    public String getFieldTo19() {
        return fieldTo19;
    }

    public String getFieldTo20() {
        return fieldTo20;
    }

    public void setFieldTo1(String fieldTo1) {
        this.fieldTo1 = fieldTo1;
    }

    public void setFieldTo2(String fieldTo2) {
        this.fieldTo2 = fieldTo2;
    }

    public void setFieldTo3(String fieldTo3) {
        this.fieldTo3 = fieldTo3;
    }

    public void setFieldTo4(String fieldTo4) {
        this.fieldTo4 = fieldTo4;
    }

    public void setFieldTo5(String fieldTo5) {
        this.fieldTo5 = fieldTo5;
    }

    public void setFieldTo6(String fieldTo6) {
        this.fieldTo6 = fieldTo6;
    }

    public void setFieldTo7(String fieldTo7) {
        this.fieldTo7 = fieldTo7;
    }

    public void setFieldTo8(String fieldTo8) {
        this.fieldTo8 = fieldTo8;
    }

    public void setFieldTo9(String fieldTo9) {
        this.fieldTo9 = fieldTo9;
    }

    public void setFieldTo10(String fieldTo10) {
        this.fieldTo10 = fieldTo10;
    }

    public void setFieldTo11(String fieldTo11) {
        this.fieldTo11 = fieldTo11;
    }

    public void setFieldTo12(String fieldTo12) {
        this.fieldTo12 = fieldTo12;
    }

    public void setFieldTo13(String fieldTo13) {
        this.fieldTo13 = fieldTo13;
    }

    public void setFieldTo14(String fieldTo14) {
        this.fieldTo14 = fieldTo14;
    }

    public void setFieldTo15(String fieldTo15) {
        this.fieldTo15 = fieldTo15;
    }

    public void setFieldTo16(String fieldTo16) {
        this.fieldTo16 = fieldTo16;
    }

    public void setFieldTo17(String fieldTo17) {
        this.fieldTo17 = fieldTo17;
    }

    public void setFieldTo18(String fieldTo18) {
        this.fieldTo18 = fieldTo18;
    }

    public void setFieldTo19(String fieldTo19) {
        this.fieldTo19 = fieldTo19;
    }

    public void setFieldTo20(String fieldTo20) {
        this.fieldTo20 = fieldTo20;
    }

    // search result
    private String column1[];
    private String column2[];
    private String column3[];
    private String column4[];
    private String column5[];
    private String column6[];
    private String column7[];
    private String column8[];
    private String column9[];
    private String column10[];
    private String column11[];
    private String column12[];
    private String column13[];
    private String column14[];
    private String column15[];
    private String column16[];
    private String column17[];
    private String column18[];
    private String column19[];
    private String column20[];

    public String[] getColumn1() {
        return column1;
    }

    public String[] getColumn2() {
        return column2;
    }

    public String[] getColumn3() {
        return column3;
    }

    public String[] getColumn4() {
        return column4;
    }

    public String[] getColumn5() {
        return column5;
    }

    public String[] getColumn6() {
        return column6;
    }

    public String[] getColumn7() {
        return column7;
    }

    public String[] getColumn8() {
        return column8;
    }

    public String[] getColumn9() {
        return column9;
    }

    public String[] getColumn10() {
        return column10;
    }

    public String[] getColumn11() {
        return column11;
    }

    public String[] getColumn12() {
        return column12;
    }

    public String[] getColumn13() {
        return column13;
    }

    public String[] getColumn14() {
        return column14;
    }

    public String[] getColumn15() {
        return column15;
    }

    public String[] getColumn16() {
        return column16;
    }

    public String[] getColumn17() {
        return column17;
    }

    public String[] getColumn18() {
        return column18;
    }

    public String[] getColumn19() {
        return column19;
    }

    public String[] getColumn20() {
        return column20;
    }

    public void setColumn1(String[] column1) {
        this.column1 = column1;
    }

    public void setColumn2(String[] column2) {
        this.column2 = column2;
    }

    public void setColumn3(String[] column3) {
        this.column3 = column3;
    }

    public void setColumn4(String[] column4) {
        this.column4 = column4;
    }

    public void setColumn5(String[] column5) {
        this.column5 = column5;
    }

    public void setColumn6(String[] column6) {
        this.column6 = column6;
    }

    public void setColumn7(String[] column7) {
        this.column7 = column7;
    }

    public void setColumn8(String[] column8) {
        this.column8 = column8;
    }

    public void setColumn9(String[] column9) {
        this.column9 = column9;
    }

    public void setColumn10(String[] column10) {
        this.column10 = column10;
    }

    public void setColumn11(String[] column11) {
        this.column11 = column11;
    }

    public void setColumn12(String[] column12) {
        this.column12 = column12;
    }

    public void setColumn13(String[] column13) {
        this.column13 = column13;
    }

    public void setColumn14(String[] column14) {
        this.column14 = column14;
    }

    public void setColumn15(String[] column15) {
        this.column15 = column15;
    }

    public void setColumn16(String[] column16) {
        this.column16 = column16;
    }

    public void setColumn17(String[] column17) {
        this.column17 = column17;
    }

    public void setColumn18(String[] column18) {
        this.column18 = column18;
    }

    public void setColumn19(String[] column19) {
        this.column19 = column19;
    }

    public void setColumn20(String[] column20) {
        this.column20 = column20;
    }

    private String[] column21;
    private String[] column22;
    private String[] column23;
    private String[] column24;
    private String[] column25;
    private String[] column26;
    private String[] column27;
    private String[] column28;
    private String[] column29;
    private String[] column30;
    private String[] column31;
    private String[] column32;
    private String[] column33;
    private String[] column34;
    private String[] column35;
    private String[] column36;
    private String[] column37;
    private String[] column38;
    private String[] column39;
    private String[] column40;
    private String[] column41;
    private String[] column42;
    private String[] column43;
    private String[] column44;
    private String[] column45;
    private String[] column46;
    private String[] column47;
    private String[] column48;
    private String[] column49;
    private String[] column50;

    public String[] getColumn21() {
        return column21;
    }

    public String[] getColumn22() {
        return column22;
    }

    public String[] getColumn23() {
        return column23;
    }

    public String[] getColumn24() {
        return column24;
    }

    public String[] getColumn25() {
        return column25;
    }

    public String[] getColumn26() {
        return column26;
    }

    public String[] getColumn27() {
        return column27;
    }

    public String[] getColumn28() {
        return column28;
    }

    public String[] getColumn29() {
        return column29;
    }

    public String[] getColumn30() {
        return column30;
    }

    public String[] getColumn31() {
        return column31;
    }

    public String[] getColumn32() {
        return column32;
    }

    public String[] getColumn33() {
        return column33;
    }

    public String[] getColumn34() {
        return column34;
    }

    public String[] getColumn35() {
        return column35;
    }

    public String[] getColumn36() {
        return column36;
    }

    public String[] getColumn37() {
        return column37;
    }

    public String[] getColumn38() {
        return column38;
    }

    public String[] getColumn39() {
        return column39;
    }

    public String[] getColumn40() {
        return column40;
    }

    public String[] getColumn41() {
        return column41;
    }

    public String[] getColumn42() {
        return column42;
    }

    public String[] getColumn43() {
        return column43;
    }

    public String[] getColumn44() {
        return column44;
    }

    public String[] getColumn45() {
        return column45;
    }

    public String[] getColumn46() {
        return column46;
    }

    public String[] getColumn47() {
        return column47;
    }

    public String[] getColumn48() {
        return column48;
    }

    public String[] getColumn49() {
        return column49;
    }

    public String[] getColumn50() {
        return column50;
    }

    public void setColumn21(String[] column21) {
        this.column21 = column21;
    }

    public void setColumn22(String[] column22) {
        this.column22 = column22;
    }

    public void setColumn23(String[] column23) {
        this.column23 = column23;
    }

    public void setColumn24(String[] column24) {
        this.column24 = column24;
    }

    public void setColumn25(String[] column25) {
        this.column25 = column25;
    }

    public void setColumn26(String[] column26) {
        this.column26 = column26;
    }

    public void setColumn27(String[] column27) {
        this.column27 = column27;
    }

    public void setColumn28(String[] column28) {
        this.column28 = column28;
    }

    public void setColumn29(String[] column29) {
        this.column29 = column29;
    }

    public void setColumn30(String[] column30) {
        this.column30 = column30;
    }

    public void setColumn31(String[] column31) {
        this.column31 = column31;
    }

    public void setColumn32(String[] column32) {
        this.column32 = column32;
    }

    public void setColumn33(String[] column33) {
        this.column33 = column33;
    }

    public void setColumn34(String[] column34) {
        this.column34 = column34;
    }

    public void setColumn35(String[] column35) {
        this.column35 = column35;
    }

    public void setColumn36(String[] column36) {
        this.column36 = column36;
    }

    public void setColumn37(String[] column37) {
        this.column37 = column37;
    }

    public void setColumn38(String[] column38) {
        this.column38 = column38;
    }

    public void setColumn39(String[] column39) {
        this.column39 = column39;
    }

    public void setColumn40(String[] column40) {
        this.column40 = column40;
    }

    public void setColumn41(String[] column41) {
        this.column41 = column41;
    }

    public void setColumn42(String[] column42) {
        this.column42 = column42;
    }

    public void setColumn43(String[] column43) {
        this.column43 = column43;
    }

    public void setColumn44(String[] column44) {
        this.column44 = column44;
    }

    public void setColumn45(String[] column45) {
        this.column45 = column45;
    }

    public void setColumn46(String[] column46) {
        this.column46 = column46;
    }

    public void setColumn47(String[] column47) {
        this.column47 = column47;
    }

    public void setColumn48(String[] column48) {
        this.column48 = column48;
    }

    public void setColumn49(String[] column49) {
        this.column49 = column49;
    }

    public void setColumn50(String[] column50) {
        this.column50 = column50;
    }

    public String getNeedResize() {
        return needResize;
    }

    public void setNeedResize(String needResize) {
        this.needResize = needResize;
    }

    public void otherReset(ActionMapping mapping, HttpServletRequest request) {
        String emptyString = "";
        pageEvent = emptyString;
    }

    public void otherValidate(ActionErrors errors) {

    }

    public String getFormFieldVal(int idx) {
        switch (idx) {
            case 1:
                return getField1();

            case 2:
                return getField2();

            case 3:
                return getField3();

            case 4:
                return getField4();

            case 5:
                return getField5();

            case 6:
                return getField6();

            case 7:
                return getField7();

            case 8:
                return getField8();

            case 9:
                return getField9();

            case 10:
                return getField10();

            case 11:
                return getField11();

            case 12:
                return getField12();

            case 13:
                return getField13();

            case 14:
                return getField14();

            case 15:
                return getField15();

            case 16:
                return getField16();

            case 17:
                return getField17();

            case 18:
                return getField18();

            case 19:
                return getField19();

            case 20:
                return getField20();

            default:
                return "";
        }
    }

    public String getFormFieldToVal(int idx) {
        switch (idx) {
            case 1:
                return getFieldTo1();

            case 2:
                return getFieldTo2();

            case 3:
                return getFieldTo3();

            case 4:
                return getFieldTo4();

            case 5:
                return getFieldTo5();

            case 6:
                return getFieldTo6();

            case 7:
                return getFieldTo7();

            case 8:
                return getFieldTo8();

            case 9:
                return getFieldTo9();

            case 10:
                return getFieldTo10();

            case 11:
                return getFieldTo11();

            case 12:
                return getFieldTo12();

            case 13:
                return getFieldTo13();

            case 14:
                return getFieldTo14();

            case 15:
                return getFieldTo15();

            case 16:
                return getFieldTo16();

            case 17:
                return getFieldTo17();

            case 18:
                return getFieldTo18();

            case 19:
                return getFieldTo19();

            case 20:
                return getFieldTo20();

            default:
                return "";
        }
    }

    public String replaceFilterVal(String inWhere) {
        int fromIdx = 0;
        int fieldIdx = 0;
        String tmpWhere = "";

        tmpWhere = inWhere;

        while (true) {
            if (fromIdx >= tmpWhere.length()) {
                break;
            }

            int whereIdx = -1;
            String tmp = "";

            whereIdx = tmpWhere.indexOf("?field", fromIdx);
            if (whereIdx == -1) {
                break;
            }

            if ((whereIdx + "?field".length()) >= tmpWhere.length()) {
                break;
            }

            if ((whereIdx + "?field".length() + 1) == tmpWhere.length()) {
                tmp = tmpWhere.substring(whereIdx + "?field".length(), whereIdx + "?field".length() + 1);
            } else {
                tmp = tmpWhere.substring(whereIdx + "?field".length(), whereIdx + "?field".length() + 2);
            }

            if (!CommonUtil.isValidNumber(tmp.substring(0, 1))) {
                fromIdx = whereIdx + "?field".length();
                continue;
            }

            if (tmp.length() > 1) {
                if (!CommonUtil.isValidNumber(tmp.substring(1, 2))) {
                    fieldIdx = Integer.parseInt(tmp.substring(0, 1));
                } else {
                    fieldIdx = Integer.parseInt(tmp.substring(0, 2));
                }
            } else {
                fieldIdx = Integer.parseInt(tmp.substring(0, 1));
            }

            tmpWhere = CommonUtil.stringRpl(tmpWhere, "?field" + fieldIdx, "'"
                    + CommonUtil.nullToString(getFormFieldVal(fieldIdx)) + "'");

            fromIdx = whereIdx + ("'" + CommonUtil.nullToString(getFormFieldVal(fieldIdx)) + "'").length();
        }

        // System.out.println(tmpWhere);
        return tmpWhere;

    }

    public String replaceFilterToVal(String inWhere) {
        int fromIdx = 0;
        int fieldIdx = 0;
        String tmpWhere = "";

        tmpWhere = inWhere;

        while (true) {
            if (fromIdx >= tmpWhere.length()) {
                break;
            }

            int whereIdx = -1;
            String tmp = "";

            whereIdx = tmpWhere.indexOf("?fieldTo", fromIdx);
            if (whereIdx == -1) {
                break;
            }

            if ((whereIdx + "?fieldTo".length()) >= tmpWhere.length()) {
                break;
            }

            if ((whereIdx + "?fieldTo".length() + 1) == tmpWhere.length()) {
                tmp = tmpWhere.substring(whereIdx + "?fieldTo".length(), whereIdx + "?fieldTo".length() + 1);
            } else {
                tmp = tmpWhere.substring(whereIdx + "?fieldTo".length(), whereIdx + "?fieldTo".length() + 2);
            }

            if (!CommonUtil.isValidNumber(tmp.substring(0, 1))) {
                fromIdx = whereIdx + "?fieldTo".length();
                continue;
            }

            if (tmp.length() > 1) {
                if (!CommonUtil.isValidNumber(tmp.substring(1, 2))) {
                    fieldIdx = Integer.parseInt(tmp.substring(0, 1));
                } else {
                    fieldIdx = Integer.parseInt(tmp.substring(0, 2));
                }
            } else {
                fieldIdx = Integer.parseInt(tmp.substring(0, 1));
            }

            tmpWhere = CommonUtil.stringRpl(tmpWhere, "?fieldTo" + fieldIdx, "'"
                    + CommonUtil.nullToString(getFormFieldToVal(fieldIdx)) + "'");

            fromIdx = whereIdx + ("'" + CommonUtil.nullToString(getFormFieldToVal(fieldIdx)) + "'").length();
        }

        // System.out.println(tmpWhere);
        return tmpWhere;

    }

    public String getResizeToX() {
        return resizeTo[0];
    }

    public String getResizeToY() {
        return resizeTo[1];
    }

    public void setResizeTo(String[] resizeTo) {
        this.resizeTo = resizeTo;
    }

	public boolean isShowFromTo() {
		return showFromTo;
	}

	public void setShowFromTo(boolean showFromTo) {
		this.showFromTo = showFromTo;
	}

	public boolean isShowOkCancelBtn() {
		return showOkCancelBtn;
	}

	public void setShowOkCancelBtn(boolean showOkCancelBtn) {
		this.showOkCancelBtn = showOkCancelBtn;
	}

	public boolean isShowSearchBtn() {
		return showSearchBtn;
	}

	public void setShowSearchBtn(boolean showSearchBtn) {
		this.showSearchBtn = showSearchBtn;
	}

	public boolean isShowSelectBox() {
		return showSelectBox;
	}

	public void setShowSelectBox(boolean showSelectBox) {
		this.showSelectBox = showSelectBox;
	}

}
